﻿using Microsoft.Xaml.Behaviors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;

namespace HotelManager.Common.Behaviors
{
    public class MouseWheelBehavior:Behavior<TextBox>
    {
        public int MaxValue { get; set; }
        public int MinValue { get; set; }
        public int Scale { get; set; } = 1;
        protected override void OnAttached()
        {
            AssociatedObject.MouseWheel += MouseWheel;
        }

        private void MouseWheel(object sender, MouseWheelEventArgs e)
        {
            var value = int.Parse(AssociatedObject.Text);
            if(e.Delta>0)
            {
                value += Scale;
            }
            else
            {
                value -= Scale;
            }
            if (value > MaxValue)
                value = MaxValue;
            AssociatedObject.Text = value.ToString();
        }
    }
}
